package com.eeepay.eeepay_v2.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.util.Constant;
import com.eeepay.v2_library.view.LeftRightText;

import cn.eeepay.api.grpc.nano.MerAddModular;

/**
 * Created by Ching on 2016/4/13.
 * 进件查询费率
 */
public class RateQueryAdapter extends BaseAdapter {

    private MerAddModular.MerServiceRate[] rateList;
    private Context mContext;

    public RateQueryAdapter(Context mContext) {
        this.mContext = mContext;

    }

    public void addAll(MerAddModular.MerServiceRate[] rateList) {
        this.rateList = rateList;
        notifyDataSetChanged();
    }

//    public List<RateInfo> getDatas() {
//        return rateList;
//    }

    public MerAddModular.MerServiceRate[] getDatas() {
        return rateList;
    }

    @Override
    public int getCount() {
        return rateList.length;
    }

    @Override
    public Object getItem(int position) {
        return rateList[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        MerAddModular.MerServiceRate rateInfo = rateList[position];
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_into_query_rate, parent, false);
            holder = new ViewHolder();
            holder.serName = (LeftRightText) convertView.findViewById(R.id.lrt_service_name);
            holder.cardType = (LeftRightText) convertView.findViewById(R.id.lrt_service_card_type);
            holder.serTime = (LeftRightText) convertView.findViewById(R.id.lrt_service_time);
            holder.rateLrt = (LeftRightText) convertView.findViewById(R.id.lrt_into_query_rate);
            convertView.setTag(holder);
        }

        holder.serName.setRightText(rateInfo.serviceName);//服务名称
//        int type = Integer.parseInt(rateInfo.cardType);//卡类型
//        String cardType = null;
//        switch (type) {
//            case 0:
//                cardType = "不限";
//                break;
//            case 1:
//                cardType = "信用卡";
//                break;
//            case 2:
//                cardType = "储蓄卡";
//                break;
//        }
        holder.cardType.setRightText(rateInfo.cardType);
//        int time = Integer.parseInt(rateInfo.holidaysMark);//服务时间
//        String serviceTime = null;
//        switch (time) {
//            case 0:
//                serviceTime = "不限";
//                break;
//            case 1:
//                serviceTime = "工作日";
//                break;
//            case 2:
//                serviceTime = "节假日";
//                break;
//        }
        holder.serTime.setRightText(rateInfo.holidaysMark);
//        String rate = null;
        Log.d("Rate"," rate >>> "+rateInfo.rate);
//        switch (rateInfo.rateType) {//服务费率
//            case "1"://固定金额 --> 1.00
//                rate = rateInfo.singleNumAmount;
//                break;
//            case "2"://固定费率 --> 0.38%
//                rate = rateInfo.rate + "%";
//                break;
//            case "3"://保底+封顶 --> 0~0.38%~26
//                rate = rateInfo.safeLine + "~" + rateInfo.rate + "~" + rateInfo.capping;
//                break;
//            case "4"://费率+固定金额 --> 0.38+1
//                rate = rateInfo.rate + "+" + rateInfo.singleNumAmount;
//                break;
//            case "5"://
//                rate = rateInfo.ladder1Rate + "%~" + rateInfo.ladder1Max + "~" + rateInfo.ladder2Rate+"%";
//                break;
//        }
        holder.rateLrt.setRightText(rateInfo.rate);
        return convertView;
    }

    class ViewHolder {
        public LeftRightText serName, cardType, serTime, type, rateLrt;
        //        public LabelEditText rate;
//        public TextView rate2Tv, rate3Tv, rate4Tv, rate5Ldr1Tv, rate5Ldr2Tv;
//        public TextView safeLine, capping, amount4, ldr1Max, amount1;
    }


}

//            holder.amount1 = (TextView) convertView.findViewById(R.id.tv_amount1);
//            RelativeLayout rate2Ll = (RelativeLayout) convertView.findViewById(R.id.ll_query_rate2);
//            LinearLayout rate3Ll = (LinearLayout) convertView.findViewById(R.id.ll_rate3);
//            RelativeLayout rate4Ll = (RelativeLayout) convertView.findViewById(R.id.ll_rate4);
//            RelativeLayout rate5Rl = (RelativeLayout) convertView.findViewById(R.id.rl_rate5);
//            switch (Integer.parseInt(rateInfo.rateType)) {
//                case 1:
//                    holder.amount1.setVisibility(View.VISIBLE);
//                    holder.amount1.setText(rateInfo.singleNumAmount);
//                    break;
//                case 2:
//                    holder.rate2Tv = (TextView) convertView.findViewById(R.id.tv_rate2);
//
//                    rate2Ll.setVisibility(View.VISIBLE);
//                    holder.amount1.setVisibility(View.GONE);
//                    rate3Ll.setVisibility(View.GONE);
//                    rate4Ll.setVisibility(View.GONE);
//                    rate5Rl.setVisibility(View.GONE);
//
//                    Log.d("saki"," 111--> "+rateInfo.rate);
//                    holder.rate2Tv.setText(rateInfo.rate);
//                    holder.rate2Tv.setTag(position);
//                    break;
//                case 3:
//                    holder.rate3Tv = (TextView) convertView.findViewById(R.id.tv_rate3);
//                    holder.safeLine = (TextView) convertView.findViewById(R.id.tv_safeLine);
//                    holder.capping = (TextView) convertView.findViewById(R.id.tv_capping);
//
//                    rate3Ll.setVisibility(View.VISIBLE);
//                    holder.amount1.setVisibility(View.GONE);
//                    rate2Ll.setVisibility(View.GONE);
//                    rate4Ll.setVisibility(View.GONE);
//                    rate5Rl.setVisibility(View.GONE);
//
//                    holder.rate3Tv.setText(rateInfo.rate);
//                    holder.safeLine.setText(rateInfo.safeLine);
//                    Log.d("lee", " rateInfo.capping " + rateInfo.capping);
//                    holder.capping.setText(rateInfo.capping);
//                    holder.rate3Tv.setTag(position);
//                    break;
//                case 4:
//                    holder.rate4Tv = (TextView) convertView.findViewById(R.id.tv_rate4);
//                    holder.amount4 = (TextView) convertView.findViewById(R.id.tv_amount4);
//
//                    rate4Ll.setVisibility(View.VISIBLE);
//                    holder.amount1.setVisibility(View.GONE);
//                    rate2Ll.setVisibility(View.GONE);
//                    rate3Ll.setVisibility(View.GONE);
//                    rate5Rl.setVisibility(View.GONE);
//
//                    holder.rate4Tv.setText(rateInfo.rate);
//                    holder.amount4.setText(rateInfo.singleNumAmount);
//                    holder.rate4Tv.setTag(position);
//                    break;
//                case 5:
//                    holder.rate5Ldr1Tv = (TextView) convertView.findViewById(R.id.tv_ldr1_rate);
//                    holder.rate5Ldr2Tv = (TextView) convertView.findViewById(R.id.tv_ldr2_rate);
//                    holder.ldr1Max = (TextView) convertView.findViewById(R.id.tv_ldr1_max);
//
//                    rate5Rl.setVisibility(View.VISIBLE);
//                    holder.amount1.setVisibility(View.GONE);
//                    rate2Ll.setVisibility(View.GONE);
//                    rate3Ll.setVisibility(View.GONE);
//                    rate4Ll.setVisibility(View.GONE);
//
//                    holder.rate5Ldr1Tv.setText(rateInfo.ladder1Rate);
//                    holder.rate5Ldr2Tv.setText(rateInfo.ladder2Rate);
//                    holder.ldr1Max.setText(rateInfo.ladder1Max);
//                    holder.rate5Ldr1Tv.setTag(position);
//                    holder.rate5Ldr2Tv.setTag(position);
//                    break;
//            }